# vim: set noexpandtab tabstop=4 softtabstop=4 shiftwidth=4:

CC       = g++
CFLAGS   = -Wall -ggdb
LDFLAGS  = 
LIBS     =
TARGET   = chromium
INCLUDES = -I.
SOURCES  = $(wildcard ./chrome/app/*.cc) $(wildcard ./content/app/*.cc)
OBJS     = $(patsubst %.cc,%.o,$(SOURCES))
	
$(TARGET): $(OBJS)
	$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS) $(LIBS)
	rm -rf *.o

%.o: %.cc
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

.PHONY: all make_all_sub_dir clean make_clean_sub_dir c rebuild r

all: $(TARGET)

make_all_sub_dir:
	@make_all_sub_dir()                                    \
	{                                                      \
	    for dir in `ls`; do                                \
	        if [ -d $$dir -a $$dir = "third-party" ]; then \
	            continue;                                  \
	        fi;                                            \
	        if [ -d $$dir ]; then                          \
	            cd $$dir;                                  \
	            if [ -f makefile -o -f Makefile ]; then    \
	                make;                                  \
	            fi;                                        \
	            make_all_sub_dir;                          \
	            cd ..;                                     \
	        fi;                                            \
	    done;                                              \
	};                                                     \
	make_all_sub_dir 

clean: make_clean_sub_dir
	rm -rf *.o
	rm -rf $(TARGET)

make_clean_sub_dir:
	@make_clean_sub_dir()                                  \
	{                                                      \
	    for dir in `ls`; do                                \
	        if [ -d $$dir -a $$dir = "third-party" ]; then \
	            continue;                                  \
	        fi;                                            \
	        if [ -d $$dir ]; then                          \
	            cd $$dir;                                  \
	            if [ -f makefile -o -f Makefile ]; then    \
	                make clean;                            \
	            fi;                                        \
	            make_clean_sub_dir;                        \
	            cd ..;                                     \
	        fi;                                            \
	    done;                                              \
	};                                                     \
	make_clean_sub_dir

c: clean
rebuild: clean all
r: rebuild
